package com.example.group.network.express_plus_app.ui.mine;

import android.content.Context;
import android.text.NoCopySpan;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.android.volley.toolbox.ImageLoader;
import com.example.group.network.express_plus_app.Dao.AppDatabase;
import com.example.group.network.express_plus_app.Dao.UserDao.UserDao;
import com.example.group.network.express_plus_app.data.model.LoggedInUser;

import java.util.List;

public class MineViewModel extends ViewModel {

    AppDatabase appDatabase;
    MutableLiveData<LoggedInUser> loggedInUser=new MutableLiveData<>();

    public MineViewModel(Context context) {
        appDatabase= AppDatabase.getsInstance(context);
    }

    public LiveData<LoggedInUser> getUser() {
        return loggedInUser;
    }


    //获取储存在数据库个人用户信息
    public void getUserFromSQ(){
        UserDao userDao = appDatabase.userDao();
        List<LoggedInUser> loggedInUsers = userDao.loadUsers();
        LoggedInUser user=null;
        if (loggedInUsers.size()>0){
            user = loggedInUsers.get(0);
        }
        loggedInUser.setValue(user);
    }

}